package com.yami.shop.api.controller;

import com.yami.shop.bean.meituan.MeiTuanOrderStatus;
import com.yami.shop.bean.meituan.OrderStatusInfo;
import com.yami.shop.service.OrderService;
import com.yami.shop.service.OrderStatusInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/MeituanOrderStatusInfo")
public class OrderStatusCallbackController {

    @Autowired
    private OrderStatusInfoService orderStatusInfoService;

    @Autowired
    private OrderService orderService;

    //获取订单状态改变回调
    @PostMapping("/getStatus")
    public ResponseEntity<Map> getOrderStatus( MeiTuanOrderStatus meiTuanOrderStatus){
        Map map = new HashMap();
        if(meiTuanOrderStatus!=null){
            OrderStatusInfo orderStatusInfo = new OrderStatusInfo();
            orderStatusInfo.setMtPeisongId(meiTuanOrderStatus.getMt_peisong_id());
            orderStatusInfo.setDeliveryId(meiTuanOrderStatus.getDelivery_id());
            orderStatusInfo.setOrderId(meiTuanOrderStatus.getOrder_id());
            orderStatusInfo.setCancelReason(meiTuanOrderStatus.getCancel_reason());
            orderStatusInfo.setStatus(meiTuanOrderStatus.getStatus());
            orderStatusInfo.setCancelReasonId(meiTuanOrderStatus.getCancel_reason_id());
            orderStatusInfo.setCourierName(meiTuanOrderStatus.getCourier_name());
            orderStatusInfo.setCourierPhone(meiTuanOrderStatus.getCourier_phone());
            map = orderStatusInfoService.dealOrderStatus(orderStatusInfo);
        }
        return ResponseEntity.ok(map);
    }

}
